package com.example.lisongyu;



import android.graphics.drawable.Drawable;
import android.os.Build;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

public class XiangceActivity extends AppCompatActivity implements View.OnClickListener {
    private Button id_course1029_bt_11s;
    private Button id_course1029_bt_21s;
    private ImageView id_course1029_iv_11s;

    Drawable[] images = new Drawable[6];
    int index = 0;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiangce);
        initView();  //step2:创建初始化的方法

        images[0] = getDrawable(R.drawable.img01);
        images[1] = getDrawable(R.drawable.img02);
        images[2] = getDrawable(R.drawable.img03);
        images[3] = getDrawable(R.drawable.img04);
        images[4] = getDrawable(R.drawable.img05);
        images[5] = getDrawable(R.drawable.img06);

    }

    private void initView() {
        id_course1029_bt_11s = findViewById(R.id.id_course1029_bt_1);   //第三步：找ID
        id_course1029_bt_21s = findViewById(R.id.id_course1029_bt_2);
        id_course1029_iv_11s = findViewById(R.id.id_course1029_iv_1);

        id_course1029_bt_11s.setOnClickListener(this);  //step4:设置监听
        id_course1029_bt_21s.setOnClickListener(this);
    }


    public void onClick(View v) {
        switch (v.getId()){
            case R.id.id_course1029_bt_2:  //step5:跳转
                index++;
                if(index>=6)index=0;
                id_course1029_iv_11s.setImageDrawable(images[index]);
                break;
            case R.id.id_course1029_bt_1:
                index--;
                if(index<=-1)index=3;
                id_course1029_iv_11s.setImageDrawable(images[index]);
                break;

//                Intent intent = new Intent();   //ctrl+/注释
//                intent.setClass(this,Main2Activity.class);
//                startActivity(intent);
//题目：添加上一页按钮，实现往上翻页，同时在按钮下方显示所有的图片
        }
    }
}